#ifndef WIDGET_H
#define WIDGET_H

#include "mqtt_dev/mqtt_dev.h"
#include "pub_aliyun_thread/pub_aliyun_thread.h"
#include <QWidget>
#include "rs485_dev/rs485_dev.h"
#include "pwm/gpio_pwm.h"
#include <QNetworkConfigurationManager>
#include <QTimer>
#include "can_bus/dialog_can_config.h"
#include <QCanBusDevice>
#include <QCanBus>
#include "dialog_off_line_config.h"
#include <aliyun_link_mode/dtu_4g.h>
#include "set_aliyun_link_dialog.h"
#include "link_else_loongson/link_else_loongson_dialog.h"

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT
private:
    mqtt_dev *pcf8591_mqtt_dev = nullptr;
    mqtt_dev *off_line_dev = nullptr;
    MQTTClient_connectOptions conn_opts;
    MQTTClient_willOptions will_opts;
    pub_aliyun_thread *pub_thread = nullptr;
    gpio_pwm *pwm = nullptr;
    QNetworkConfigurationManager *manager = nullptr;    //用于监视网络连接状态
    QTimer *timer = nullptr;
    dialog_can_config *can_config = nullptr;
    set_aliyun_link_dialog *aliyun_link_mode = nullptr;
    dialog_off_line_config *off_line_config = nullptr;
    QCanBusDevice *can_dev = nullptr;
    dtu_4G *dtu_4g_dev = nullptr;   //4GDTU模块
    link_else_loongson_dialog *link_else_loongson = nullptr;

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

    void set_aliyun_con_btn_text(QString text);

    dtu_4G *getDtu_4g_dev() const;

private slots:
    void on_aliyun_con_btn_clicked();

    void on_pwm_out_btn_clicked();

    void on_pwm_duty_sli_valueChanged(int value);

    void on_pwm_stop_out_btn_clicked();

    void on_set_off_line_btn_clicked();

    void net_dis_handler(bool isOnline);

    void off_line_data_pub(void);

    void show_data(struct gather_data val);

    void on_can_con_btn_clicked();

    /* CAN接收消息 */
    void receivedFrames();

    /* 处理can错误 */
    void canDeviceErrors(QCanBusDevice::CanBusError) const;

    void on_can_data_send_btn_clicked();

    void on_set_can_config_btn_clicked();

    void on_aliyun_connect_config_btn_clicked();

    /* 4GDTU模块成功连接阿里云 */
    void dtu_4g_connect_aly_ok(void);

    /* 4GDTU模块断开与阿里云的连接 */
    void dtu_4g_disconnect_aly();

    void on_dtu_4g_reset_btn_clicked();

    void dtu_4g_dev_reset_ok();     //4GDTU设备重启完毕


    void on_link_else_loongson_clicked();

private:
    Ui::Widget *ui;
};

#endif // WIDGET_H
